package 力扣_链表.简单;

/**
 * @author zx
 * @create 2022-08-15 17:27
 */
public class 面试题_分割链表 {
    public ListNode partition(ListNode head, int x) {
        ListNode small = new ListNode(101);
        ListNode smallHead = small;
        ListNode large = new ListNode(101);
        ListNode largeHead = large;
        while(head != null){
            if(head.val < x){
                small.next = head;
                small = small.next;
            }else{
                large.next = head;
                large = large.next;
            }
            head = head.next;
        }
        large.next = null;//注意这里必须有这个置空
        small.next = largeHead.next;
        return smallHead.next;
    }
}
class ListNode {
    int val;
    ListNode next;
    ListNode(int val){
        this.val = val;
        next = null;
    }
}